//
//  QLPublishSeekHelpVC.m
//  神约
//
//  Created by qlwl on 17/2/15.
//  Copyright © 2017年 qlwl. All rights reserved.
//

#import "QLPublishSeekHelpVC.h"
#import "QLPublishSeekHelpCell.h"
#import "QLPublishSeekHelpModel.h"

@interface QLPublishSeekHelpVC ()
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) QLPublishSeekHelpModel * helpModel ; //
@end

@implementation QLPublishSeekHelpVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
#pragma mark property
- (QLPublishSeekHelpModel *)helpModel
{
    if (!_helpModel) {
        _helpModel = [[QLPublishSeekHelpModel alloc] init];
        _helpModel.title = self.name;
        _helpModel.address = @"金星路24号";
    }
    return _helpModel;
}

#pragma mark TabDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else if (section == 1){
        if (self.helpModel.isPay) {
            return 3;
        }
        return 1;
    }else if (section == 2){
        if (self.helpModel.serviceMode == 0) {
            return 5;
        }
        return 4;
    }else if (section == 3){
        return 1;
    }
    return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        QLPublishSeekHelpCell * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPublishSeekHelpCell"];
        cell.titLab.text = @"求助内容";
        [cell.helpTypeBtn setTitle:self.helpModel.title forState:UIControlStateNormal];
        return cell;
    }else if (indexPath.section == 1){
        if (indexPath.row == 0) {
            QLPublishSeekHelpCell2 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPublishSeekHelpCell2"];
            cell.titLab.text = @"费用要求";
            cell.isPay = self.helpModel.isPay;
            cell.isPayClick = ^(BOOL isPay){
                self.helpModel.isPay = isPay;
                [self.tableView reloadData];
            };
            return cell;
        }else if (indexPath.row == 1){
            QLPublishSeekHelpCell3 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPublishSeekHelpCell3"];
            cell.titLab.text = @"请输入价格";
            cell.textField.text = self.helpModel.price;
            cell.priceChanged = ^(NSString * price){
                self.helpModel.price = price;
            };
            return cell;
        }else if (indexPath.row == 2){
            QLPublishSeekHelpCell4 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPublishSeekHelpCell4"];
            cell.titLab.text = @"强选择单位";
            cell.unitPrice = self.helpModel.unitPrice;
            cell.byTypeChanged = ^(int unit){
                self.helpModel.unitPrice = unit;
            };
            return cell;
        }
    }else if (indexPath.section == 2){
        if (indexPath.row == 0) {
            QLPublishSeekHelpCell5 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPublishSeekHelpCell5"];
            cell.titLab.text = @"具有相关证书";
            cell.selectBtn.selected = self.helpModel.hasCertificate;
            cell.selectClick = ^(BOOL select){
                self.helpModel.hasCertificate = select;
            };
            return cell;
        }else if (indexPath.row == 1){
            QLPublishSeekHelpCell5 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPublishSeekHelpCell5"];
            cell.titLab.text = @"普通话标准";
            cell.selectBtn.selected = self.helpModel.isMandarin;
            cell.selectClick = ^(BOOL select){
                self.helpModel.isMandarin = select;
            };
            return cell;
        }else if (indexPath.row == 2){
            QLPublishSeekHelpCell6 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPublishSeekHelpCell6"];
            cell.titLab.text = @"性别要求";
            cell.sexType = self.helpModel.sexType;
            cell.sexChanged = ^(int sex){
                self.helpModel.sexType = sex;
            };
            return cell;
        }else if (indexPath.row == 3){
            QLPublishSeekHelpCell7 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPublishSeekHelpCell7"];
            cell.titLab.text = @"服务方式";
            cell.serviceMode = self.helpModel.serviceMode;
            cell.serviceModeChanged = ^(int service){
                self.helpModel.serviceMode = service;
                [self.tableView reloadData];
            };
            return cell;
        }else if (indexPath.row == 4){
            QLPublishSeekHelpCell8 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPublishSeekHelpCell8"];
            cell.titLab.text = @"地理位置";
            return cell;
        }
    }else if (indexPath.section == 3){
        QLPublishSeekHelpCell9 * cell = [tableView dequeueReusableCellWithIdentifier:@"QLPublishSeekHelpCell9"];
        cell.textView.text = self.helpModel.remark;
        cell.contentChanged = ^(NSString * remark){
            self.helpModel.remark = remark;
        };
        return cell;
    }
    return nil;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.section == 3) {
        return 120;
    }
    return 40;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 30;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 1;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return @"求助方向";
    }else if (section == 1){
        return @"邀约费用";
    }else if (section == 2){
        return @"求助对象";
    }else if (section == 3){
        return @"其他要求";
    }
    return nil;
}
- (IBAction)publishBtnClick:(id)sender {
    [self netWorking];
}

- (void) netWorking
{
    QLLoginModel * loginModel = [QLLoginModel accountFromSandbox];
    NSMutableDictionary * postDict = [[NSMutableDictionary alloc] init];
    postDict[@"cityname"] = @"北京";
    postDict[@"createby"] = loginModel.userId;
    postDict[@"category"] = [NSNumber numberWithInt:self.category];
    postDict[@"typeId"] = self.classifyId;
    postDict[@"chargeType"] = self.helpModel.isPay?@"2":@"1";
    postDict[@"servicePriceType"] = [NSNumber numberWithInt:self.helpModel.unitPrice];
    postDict[@"servicePrice"] = self.helpModel.isPay?self.helpModel.price:@"0";
    postDict[@"destination"] = self.helpModel.address;
    postDict[@"remark"] = self.helpModel.remark;
    postDict[@"sexLimit"] = [NSString stringWithFormat:@"%d",self.helpModel.sexType];
    postDict[@"serviceType"] = [NSNumber numberWithInt:self.helpModel.serviceMode];
    postDict[@"isHascertificate"] = [NSNumber numberWithInt:self.helpModel.hasCertificate];
    postDict[@"isStandardMandarin"] = [NSNumber numberWithInt:self.helpModel.isMandarin];
    [QLNetWorking postJSONWithUrl:QLPublishLifeInvitatURL parameters:postDict isJosnRequest:YES rogress:nil success:^(id result) {
        /*{
         mobileHead = {
         message = 发布成功;
         code = success;
         }
         ;
         mobileBody = {
         data = 7;
         }
         ;
         }*/
        NSLog(@"%@",result);
        if ([QLNetWorking sucess:[result objectForKey:@"mobileHead"] and:@"code" EqualToString:@"success"]) {
        
        }
    } fail:^(NSError *error) {
        
    }];
}


@end
